function main(defaultParams) {
    debugger;
    const self = this;
    const formPartEle = self.$$element("form_part_ajdtnu");

    // 执法证
    const certFormType1 = self.$$element("form_part_cf2ohq");
    // 监督证
    const certFormType2 = self.$$element("form_part_2cvrp9");

    const formEle = formPartEle.$$getRenderElement();
    const pageRenderElement = this.$$root().$parent.$parent.$parent;

    // let extraParams = self.state.extraParams;

    if (formPartEle) {
        formEle.$$validateData().then((res) => {
            if (!res.success) {
                var target = formEle.state.validate.target;
                return;
            } else {
                formEle.onSave().then((res) => {
                    if (res && res.result) {
                        const dataForSave = res.result;
                        let cardType = dataForSave['ds_tbl:t_7350da0c411d4bfe926404bb95b5d4bc'].checkbox_3hdzsi;
                        // 删除已有的数据
                        const law_std_human_type = "ds_tbl:t_fd4a2bceb59e4d4cb143ff7a73d85222";
                        const deleteSql = `DELETE('${law_std_human_type}', QUERY_EQ('std_human_id', ${dataForSave.documentNo}),'')`;
                        console.log(deleteSql);
                        api.EXEC_FORMULA(deleteSql).then((res) => {
                            const savePromises = [];

                            if (cardType.includes(1)) {
                                savePromises.push(saveForm(certFormType1, dataForSave, 1));
                            }

                            if (cardType.includes(2) || cardType.includes(3)) {
                                savePromises.push(saveForm(certFormType2, dataForSave, 2));
                            }

                            if (cardType.includes(3)) {
                                const humanData = {
                                    stdHumanId: dataForSave.documentNo,
                                    humanName: dataForSave['ds_tbl:t_7350da0c411d4bfe926404bb95b5d4bc'].text_input_244y6v,
                                    humanTypeCode: '3',
                                    humanTypeName: '法制人员'
                                };
                                insertHumanType(humanData);
                            }

                            Promise.all(savePromises)
                                .then(() => {
                                    pageRenderElement.goHistory(-1);
                                })
                                .catch((err) => {
                                    console.error("保存失败：", err);
                                });

                        });

                    }
                });


            }
        });
    }


}

/**
 * 保存证件相关的信息
 *
 */
function saveForm(certFormType, dataForSave, cardTypeValue) {
    return new Promise((resolve, reject) => {
        let formValue = dataForSave['ds_tbl:t_7350da0c411d4bfe926404bb95b5d4bc'];

        let humanData = {
            stdHumanId: dataForSave.documentNo,
            humanName: '',
            humanTypeCode: '',
            humanTypeName: ''
        }


        if (cardTypeValue === 1) {
            let cardType = certFormType.$$element("single_select_7r6jvy", true);// 证件类型
            let humanName = certFormType.$$element("text_input_388dv5", true);  // 姓名
            let cardCode = certFormType.$$element("text_input_h2rp7m", true);   // 证件号码
            let publishDate = certFormType.$$element("date_picker_duqeni", true);    // 发证日期
            let certificateValidityTimeEnd = certFormType.$$element("date_picker_a1weig", true);    // 证件有效期止
            let stdHumanId = certFormType.$$element("number_input_10gw69", true);   // 主表id

            stdHumanId.$$setValue(dataForSave.documentNo);
            humanData.stdHumanId = dataForSave.documentNo;
            humanData.humanName = formValue.text_input_244y6v;
            humanData.humanTypeCode = 1;
            humanData.humanTypeName = '执法人员'

            stdHumanId.onChange();

            cardType.$$setValue(1);
            humanName.$$setValue(formValue.text_input_244y6v);
            cardCode.$$setValue(formValue.text_input_9cvy3q);
            publishDate.$$setValue(formValue.date_picker_a98b0v);
            certificateValidityTimeEnd.$$setValue(formValue.date_picker_ana4zw);
            humanName.onChange();
            cardType.onChange();
            cardCode.onChange();
            publishDate.onChange();
            certificateValidityTimeEnd.onChange();

        } else {
            let cardType = certFormType.$$element("single_select_2r6jvy", true);// 证件类型
            let humanName = certFormType.$$element("text_input_288dv5", true);  // 姓名
            let cardCode = certFormType.$$element("text_input_22rp7m", true);   // 证件号码
            let publishDate = certFormType.$$element("date_picker_2uqeni", true);    // 发证日期
            let certificateValidityTimeEnd = certFormType.$$element("date_picker_21weig", true);    // 证件有效期止
            let stdHumanId = certFormType.$$element("number_input_20gw69", true);   // 主表id


            cardType.$$setValue(2);
            humanName.$$setValue(formValue.text_input_244y6v);
            cardCode.$$setValue(formValue.text_input_a3tlsx);
            publishDate.$$setValue(formValue.date_picker_53377w);
            certificateValidityTimeEnd.$$setValue(formValue.date_picker_ga2mcc);
            stdHumanId.$$setValue(dataForSave.documentNo);

            humanData.stdHumanId = dataForSave.documentNo;
            humanData.humanName = formValue.text_input_244y6v;
            humanData.humanTypeCode = 2;
            humanData.humanTypeName = '监督人员'

            stdHumanId.onChange();

            humanName.onChange();
            cardType.onChange();
            cardCode.onChange();
            publishDate.onChange();
            certificateValidityTimeEnd.onChange();
        }

        insertHumanType(humanData)

        // 主表id

        let formRenderEle = certFormType.$$getRenderElement()
        formRenderEle.$$validateData().then(vRes => {
            if (!(vRes && vRes.success)) {
                return;
            }
            formRenderEle.$$saveData(true).then((res) => {
                resolve(res);
            });
        });
    });

}


/**
 * 新增人员关联类型
 * @param humanData
 */
function insertHumanType(humanData) {

    const insertFields = [
        ['std_human_id', humanData.stdHumanId],
        ['human_name', `'${humanData.humanName}'`],
        ['human_type_code', `'${humanData.humanTypeCode}'`],
        ['human_type_name', `'${humanData.humanTypeName}'`],
        ['opt_type', `'I'`],
        ['create_time', 'NOW()'],
        ['update_time', 'NOW()'],
    ];

    const formattedFields = insertFields.map(([key, value]) => {
        return `'${key}',${value}`;
    });

    const law_std_human_type = "ds_tbl:t_fd4a2bceb59e4d4cb143ff7a73d85222";
    const insertSql = `INSERT('${law_std_human_type}', [${formattedFields.join(',')}])`;
    console.log(insertSql);


    api.EXEC_FORMULA(insertSql).then(res => {
        console.log(res);
    })

}

